package com.haoqizhe.kernel.mybatis.generator.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author haoqizhe.li
 * @date 2018/4/16 20:47
 */
public class StringUtils {
    /**
    * 获取格式化的类的注释
    * @param description 类描述
    * @param userName 用户名
    * @return 类的注释
    * @author haoqizhe.li
    * @date 2018/4/16 20:50
    **/
    public static String getComment(String description,String userName){
        StringBuilder sb = new StringBuilder();
        sb.append("/**").append("\n");
        sb.append(" * ").append(description).append("\n");
        sb.append(" * ").append("\n");
        sb.append(" * @author ").append(userName).append("\n");
        sb.append(" * @date "+(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")).format(new Date())).append("\n");
        sb.append(" */ ");

        return sb.toString();
    }

    /**
     * BaseUsers to baseUsers
     *
     * @param filed
     * @return
     */
    public static String toLowerCase(String filed) {
        StringBuilder sb = new StringBuilder(filed);
        sb.setCharAt(0, Character.toLowerCase(sb.charAt(0)));
        return sb.toString();
    }

    /**
     * baseUsers to BaseUsers
     * @param filed
     * @return
     */
    public static String toUpperCase(String filed){
        StringBuilder sb = new StringBuilder(filed);
        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
        return sb.toString();
    }

    /**
     * 拼接泛型
     * @param addModel
     * @param addPk
     * @param tableName
     * @param pk
     * @return
     */
    public static String getGenericity(boolean addModel,boolean addPk,String tableName,String pk){
        String str = "";
        if(addModel && addPk){
            str = "<"+tableName+","+pk+">";
        }else if(addModel && !addPk){
            str = "<"+tableName+">";
        }else if(!addModel && addPk){
            str = "<"+pk+">";
        }
        return str;
    }
}
